import 'package:flutter/material.dart';
import 'package:mall/entity/home_entity.dart';
import 'package:mall/page/home/new_product.dart';

class LayoutDemo extends StatelessWidget {
  List<FloorGoodsList> floorGoodsList;
  List<FloorGoodsList> notEmptyfloorGoodsList = List<FloorGoodsList>();

  LayoutDemo(this.floorGoodsList);

  List<Widget> buildTabList(List<FloorGoodsList> floorGoodsList) {
    var widgetList = List<Widget>();
    floorGoodsList.forEach((element) {
      widgetList.add(Tab(
        text: element.name,
      ));
    });
    return widgetList;
  }

  List<Widget> buildTabView(List<FloorGoodsList> notEmptyfloorGoodsList) {
    var widgetList = List<Widget>();
    notEmptyfloorGoodsList.forEach((floorGoods) {
      widgetList.add(Container(
        child: Column(
          children: <Widget>[
            Container(
              alignment: Alignment.center,
            ),
            ProductView(floorGoods.goodsList),
          ],
        ),
      ));
    });
    return widgetList;
  }

  List<FloorGoodsList> removeEmptyGoodsList(List<FloorGoodsList> newGoodsList) {
    newGoodsList.forEach((element) {
      if (element.goodsList.length > 0) {
        this.notEmptyfloorGoodsList.add(element);
      }
    });
    return this.notEmptyfloorGoodsList;
  }

  @override
  Widget build(BuildContext context) {
    removeEmptyGoodsList(floorGoodsList);
    return DefaultTabController(
        length: notEmptyfloorGoodsList.length,
        child: Scaffold(
            appBar: AppBar(
              backgroundColor: Colors.white,
              title: Row(
                mainAxisSize: MainAxisSize.max,
                children: <Widget>[
                  Expanded(
                    child: TabBar(
                      indicator: const BoxDecoration(),
                      indicatorSize: TabBarIndicatorSize.label,
                      indicatorWeight: 10,
                      unselectedLabelColor: Colors.amber[800],
                      labelColor: Colors.green[500],
                      tabs: this.buildTabList(this.notEmptyfloorGoodsList),
                    ),
                  )
                ],
              ),
              elevation: 0,
            ),
            body: TabBarView(
              children: buildTabView(this.notEmptyfloorGoodsList),
            )));
  }
}
